import Upload from '@/components/common/Upload.vue';
import UploadFiles from '@/components/common/UploadFile.vue';
export default {
    name: 'SceneDialog',
    props: {
        sceneProspectFlag: Boolean,
        selectionForDialog: {
            type: Object,
            default() {
                return {};
            }
        }
    },
    components: {
        Upload,
        UploadFiles
    },
    data() {
        return {
            // 上传
            uploadHttp: '/api/attachment/uploadFiles',
            // 拉取
            remoteHttp: '/api/attachment/download',
            dialogImageUrl: '',
            // dialogVisible: false,
            // disabled: false,
            workOrderStatus: '',
            // 门槛整体
            doorGlobalObj: {
                fileType: '1',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 室内天花
            insideCeilObj: {
                fileType: '2',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 室外门口
            outRoomObj: {
                fileType: '3',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 室内地面
            insideGroundObj: {
                fileType: '4',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 室内整体
            insideGlobalObj: {
                fileType: '5',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 室内墙面
            insideSurfaceObj: {
                fileType: '6',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 卫生间
            wcRoomObj: {
                fileType: '7',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 拆除项
            disposalObj: {
                fileType: '8',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 其它
            otherChooseObj: {
                fileType: '9',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 原始布局图
            originLayoutObj: {
                fileType: '10',
                fileClassify: '1',
                reconnaissanceFiles: ''
            },
            // 所有图片存储对象
            pmsWorkOrderReconnaissance: [
                {
                    fileType: '',
                    fileClassify: '',
                    reconnaissanceFiles: ''
                }
            ],
            //是否允许操作
            canReconnaissance: false
        };
    },
    created() {
        this.queryDetails();
    },
    methods: {
        //
        getToken() {
            let result = localStorage.getItem('token');
            return result;
        },
        // 查询详情数据
        async queryDetails() {
            this.$httpExt()
                .get('/api/pmsSupplierWorkOrder/queryReconnaissanceDetail', {
                    workOrderId: this.selectionForDialog.workOrderId
                })
                .then(
                    response => {
                        console.log('返回值', response.data);
                        // 所有数据
                        this.pmsWorkOrderReconnaissance = response.data.pmsWorkOrderReconnaissance;
                        // 如果是空
                        if (!this.pmsWorkOrderReconnaissance.length) return false;
                        // 现场勘察
                        this.originLayoutObj = {
                            name: response.data.fileName,
                            fileId: response.data.fileId
                        };
                        console.log('现场勘察原始布局图：', this.originLayoutObj);
                        //匹配对应的对象
                        this.pmsWorkOrderReconnaissance.forEach(item => {
                            if (item.fileType === '1') {
                                // 门槛整体
                                this.doorGlobalObj = item;
                            } else if (item.fileType === '2') {
                                // 室内天花
                                this.insideCeilObj = item;
                            } else if (item.fileType === '3') {
                                // 室外门口
                                this.outRoomObj = item;
                            } else if (item.fileType === '4') {
                                // 室内地面
                                this.insideGroundObj = item;
                            } else if (item.fileType === '5') {
                                // 室内整体
                                this.insideGlobalObj = item;
                            } else if (item.fileType === '6') {
                                // 室内墙面
                                this.insideSurfaceObj = item;
                            } else if (item.fileType === '7') {
                                // 卫生间
                                this.wcRoomObj = item;
                            } else if (item.fileType === '8') {
                                // 拆除项
                                this.disposalObj = item;
                            } else if (item.fileType === '9') {
                                // 其它
                                this.otherChooseObj = item;
                            }
                        });
                    },
                    response => {
                        this.$message({
                            type: 'error',
                            message: response.msg
                        });
                    }
                );
        },
        // 验证附件大小
        beforeUpload(file) {
            console.log('验证附件大小', file);
        },
        commonFormatData() {
            let pmsWorkOrderReconnaissance = [
                this.doorGlobalObj,
                this.insideCeilObj,
                this.outRoomObj,
                this.insideGroundObj,
                this.insideGlobalObj,
                this.insideSurfaceObj,
                this.wcRoomObj,
                this.disposalObj,
                this.otherChooseObj
            ];
            let workOrderId = this.selectionForDialog.workOrderId;
            let workOrderNo = this.selectionForDialog.workOrderNo;
            return {
                pmsWorkOrderReconnaissance: pmsWorkOrderReconnaissance,
                workOrderId: workOrderId,
                workOrderNo: workOrderNo,
                fileId: this.originLayoutObj.fileId
            };
        },
        // 提交
        submitDialog() {
            let formatData = this.commonFormatData();
            if (!this.doorGlobalObj.reconnaissanceFiles) {
                this.$message({
                    message: '请上传门楣整体图片',
                    type: 'warning'
                });
                return;
            }
            if (!this.outRoomObj.reconnaissanceFiles) {
                this.$message({
                    message: '请上传室外门口图片',
                    type: 'warning'
                });
                return;
            }
            if (!this.insideGlobalObj.reconnaissanceFiles) {
                this.$message({
                    message: '请上传室内整体图片',
                    type: 'warning'
                });
                return;
            }

            this.$httpExt()
                .post('/api/pmsSupplierWorkOrder/submitReconnaissance', formatData)
                .then(
                    response => {
                        console.log('返回值', response.data);
                        this.$message({
                            message: '提交成功',
                            type: 'success'
                        });
                        this.$emit('closeDialog');
                    },
                    response => {
                        this.$message({
                            message: response.message,
                            type: 'error'
                        });
                    }
                );
        },
        // 保存
        saveDialog() {
            let formatData = this.commonFormatData();
            this.$httpExt()
                .post('/api/pmsSupplierWorkOrder/saveReconnaissance', formatData)
                .then(
                    response => {
                        console.log('返回值', response.data);
                        this.$message({
                            message: '保存成功',
                            type: 'success'
                        });
                        this.$emit('closeDialog');
                    },
                    response => {
                        this.$message({
                            message: response.message,
                            type: 'error'
                        });
                    }
                );
        },
        clonseDialog() {
            this.$emit('closeDialog');
        }
    }
};
